 //
//  TabBarViewController.m
//  ZhaoPin
//
//  Created by 赵佟越 on 17/3/17.
//  Copyright © 2017年 zhaotongyue. All rights reserved.
//

#import "TabBarViewController.h"
#import "ViewController.h"
#import "RDVTabBarItem.h"
#import "RDVTabBarController.h"
#import "FirstGViewController.h"
#import "SecondGViewController.h"
#import "ThirtGViewController.h"
#import "FourGViewController.h"
#import "TabBarViewController.h"
#import "ViewController.h"
#import "RDVTabBarItem.h"
#import "RDVTabBarController.h"
#import "MMZCViewController.h"

@interface TabBarViewController ()<RDVTabBarControllerDelegate>
{
    NSInteger selectedTabBarIiemTag;
}
@end

@implementation TabBarViewController


- (void)viewDidLoad {
    [super viewDidLoad];

         FirstGViewController *homeView = [[FirstGViewController alloc]init];
         UINavigationController *NAV1 = [[UINavigationController alloc] initWithRootViewController:homeView];
         
         SecondGViewController *View = [[SecondGViewController alloc]init];
         UINavigationController *NAV2 = [[UINavigationController alloc] initWithRootViewController:View];
         
         ThirtGViewController *home = [[ThirtGViewController alloc]init];
         UINavigationController *NAV3 = [[UINavigationController alloc] initWithRootViewController:home];
    
         FourGViewController *My = [[FourGViewController alloc]init];
         UINavigationController *NAV4 = [[UINavigationController alloc] initWithRootViewController:My];
    
        self.viewControllers = @[NAV1,NAV2,NAV3,NAV4];
    
         [self customizeTabBarForController:self];
         self.delegate = self;
    
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    
    NSArray *tabBarItemImage_not = @[@"dsfdsffg", @"dfd",@"ef",@"fdgdfg"];
    
    NSArray *tabBarItemImages = @[@"fdgdfgfdgfgdfgsdfg", @"dfgfg",@"01010",@"sdafsdafsdf"];
    
    NSInteger index = 0;
    for (RDVTabBarItem *tabberItem in [[tabBarController tabBar] items]) {
        NSString *tempTipstr;
        switch (index) {
            case 0:
                tempTipstr = @"首页";
                break;
            case 1:
                tempTipstr = @"明星企业";
                break;
            case 2:
                tempTipstr = @"订单";
                break;
                
            case 3:
                tempTipstr = @"我的";
                break;
            default:
                break;
        }
        tabberItem.title = tempTipstr;
        
        NSDictionary *tabBarTitleUnselectedDic = @{NSForegroundColorAttributeName:yColorMain,NSFontAttributeName:[UIFont systemFontOfSize:15]};
        NSDictionary *tabBarTitleSelectedDic = @{NSForegroundColorAttributeName:kColorMain,NSFontAttributeName:[UIFont systemFontOfSize:15]};
        //修改tabberItem的title颜色
        tabberItem.selectedTitleAttributes = tabBarTitleSelectedDic;
        tabberItem.unselectedTitleAttributes = tabBarTitleUnselectedDic;
        tabberItem.tag = 100+index;
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",
                                                      [tabBarItemImages objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@",
                                                        [tabBarItemImage_not objectAtIndex:index]]];
        //设置tabberItem的选中和未选中图片
        [tabberItem setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        
        index++;
    }
}

#pragma mark - 防止tabbar双击
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    if(selectedTabBarIiemTag == viewController.rdv_tabBarItem.tag){
        
        return NO;
        
    }else {
        
        if (viewController.rdv_tabBarItem.tag == 102 && ![[NSUserDefaults standardUserDefaults] objectForKey:@"login"]) {
            MMZCViewController *vc = [[MMZCViewController alloc] init];

            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
            [self presentViewController:nav animated:true completion:^{

            }];
        }
        
        selectedTabBarIiemTag = viewController.rdv_tabBarItem.tag;
        
        
        
        return YES;
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
